
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:xim/config/route_config.dart';

/// 引导页 https://blog.csdn.net/qq_40785165/article/details/118400571
class GuidePage extends StatelessWidget {
  const GuidePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var controller = PageController();
    final pages = [page1, page2, page3];
    return Scaffold(
      body: Container(
        padding: const EdgeInsets.symmetric(vertical: 20),
        child: SafeArea(
          child: Column(
            children: [
              const Positioned(
                top: 20,
                child: Text("XIM CHAT", style: TextStyle(
                    fontSize: 18,
                    letterSpacing: 1,
                    wordSpacing: 4,
                    fontWeight: FontWeight.w600
                ),
                ),
              ),
              Expanded(
                child:PageView.builder(
                    reverse: false,
                    scrollDirection: Axis.horizontal,
                    controller: controller,
                    physics: const ClampingScrollPhysics(),
                    itemBuilder: (_, index){
                      if (index==0) return pages[0];
                      if(index<pages.length){
                        return pages[index%pages.length];
                      }
                    }
                ),
              ),
              Column(
                children: [
                  SmoothPageIndicator(
                    controller: controller,
                    count: pages.length,
                    effect: const WormEffect(
                      dotHeight: 8,
                      dotWidth: 8,
                      type: WormType.thin,
                    ),
                  ),
                  const SizedBox(height: 40,),
                  GestureDetector(
                    onTap: ()=>Routers.toLoginGuidePage(),
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 12, horizontal: 0.16.sw),
                      decoration: BoxDecoration(
                          borderRadius: const BorderRadius.all(Radius.circular(18)),
                          border: Border.all()
                      ),
                      child: const Text("开始使用", style: TextStyle(fontSize: 16),),
                    ),
                  )
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget page({required String title,required String text}) => Padding(
    padding: const EdgeInsets.all(36),
    child: Column(
      children: [
        Text(title, style: const TextStyle(fontWeight: FontWeight.w500),),
        const SizedBox(height: 20,),
        Text(
          "\t\t\t\t\t\t$text",
          style: const TextStyle(wordSpacing: 4, height: 1.3, letterSpacing: 1),
        ),
      ],
    ),
  );

  Widget get page2 => page(
    title:"加密聊天通话",
    text:"使用XIM 进行聊天通话时，XIM会你的数据在客户端进行加密传输；所以除会话成员外，都是无法获取用户的数据，包括了运维开发人员",
  );

  Widget get page1=>page(
    title:"欢迎使用 XimChat",
    text:"XimChat 是一款以用户数据隐私为核心的即使聊天软件",
  );

  Widget get page3=>page(
    title:"管理你的账号",
    text:"XimChat 采用的非传统的账号体系，使用的RSA的公私钥对作为用户的基准，不会向用户索取任何隐私数据",
  );

}



